package teamGiga.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import teamGiga.bean.MovieMemberBean;
import teamGiga.dao.MovieDao;
import action.servlet.ActionForWard;

public class MLoginAction extends Action{
	private String path;
	private boolean redirect;
	public MLoginAction(String path, boolean redirect) {
		super();
		this.path = path;
		this.redirect = redirect;
	}
	public MLoginAction() {
		super();
	}
	@Override
	public ActionForWard execute(HttpServletRequest request,
			HttpServletResponse response) {
		// TODO Auto-generated method stub
		String[]idPw=request.getParameterValues("s");
		
		try {
			MovieMemberBean memberBean=MovieDao.checkPw(idPw[0]);
			System.out.println(memberBean);
			if(memberBean.getPassword().equals(idPw[1])){
				memberBean.setPassword("********");
				//request.setAttribute("memberBean", memberBean);
				HttpSession session = request.getSession();
				session.setAttribute("memberBean", memberBean);
				session.setAttribute("mbno", memberBean.getMbno());
				session.setMaxInactiveInterval(60*60*24);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String page=request.getParameter("page");
		if(page!=null && page.equals("movieReservation")){
			this.path="/teamGiga/movieReservation.do?cmd=movieReservation";
		}
		return new ActionForWard(path, redirect);
	}
	
}
